//
//  WelcomeViewController.m
//  LINNER
//
//  Created by Kendama on 2017/10/12.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "WelcomeViewController.h"
#import "UIImage+GIF.h"
#import "ViewController.h"
#import "MainSlideViewController.h"

@interface WelcomeViewController ()


@property(nonatomic,strong) UIImageView *logoImageView;
@property(nonatomic,strong) UIImageView *labelImageView;
@property(nonatomic,strong) UIWebView *webView;


@end

@implementation WelcomeViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIStoryboard *main=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    MainSlideViewController *sliderVC = [[MainSlideViewController alloc]init];
    ViewController *homeVC = [main instantiateViewControllerWithIdentifier:@"ViewController"];
    sliderVC.rootViewController = homeVC;
    [sliderVC setupSlideStyle];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:sliderVC];
    [nav.navigationBar setHidden:YES];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //        [self startLaunchingAnimation];
        [AppDelegate globalDelegate].window.rootViewController = nav;
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIImageView *)logoImageView
{
    if(!_logoImageView)
    {
        UIView *superView = self.view;
        _logoImageView = [[UIImageView alloc]init];
        [superView addSubview:_logoImageView];
        _logoImageView.image = [UIImage sd_animatedGIFNamed:@"launch_gif2"];
//        _logoImageView.image = [UIImage sd_animatedGIFNamed:@"logo_animation"];
    }
    return _logoImageView;
}
- (UIImageView *)labelImageView
{
    if(!_labelImageView)
    {
        UIView *superView = self.view;
        _labelImageView = [[UIImageView alloc]init];
        [superView addSubview:_labelImageView];
        _labelImageView.image = [UIImage imageNamed:@"launch_bottom"];
    }
    return _labelImageView;
}

- (UIWebView *)webView
{
    if(!_webView)
    {
        UIView *superView = self.view;
        _webView = [[UIWebView alloc]init];
        [superView addSubview:_webView];
        NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"launch_gif" ofType:@"gif"]];
        _webView.userInteractionEnabled = NO;
        _webView.scalesPageToFit = YES;
        [_webView loadData:gif MIMEType:@"image/gif" textEncodingName:@"UTF-8" baseURL:nil];
        _webView.backgroundColor = [UIColor clearColor];
        _webView.opaque = NO;
    }
    return _webView;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;

    
//    [self.labelImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(superView.mas_left);
//        make.right.mas_equalTo(superView.mas_right);
//        make.bottom.mas_equalTo(superView.mas_bottom);
////        make.height.mas_equalTo(px1920Height(1919));
//    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(superView.mas_centerX);
//        make.bottom.mas_equalTo(self.labelImageView.mas_top).with.offset(px1920Height(-1020));
//        make.width.mas_equalTo(px1080Width(500));
//        make.height.mas_equalTo(px1920Height(300));
        make.center.mas_equalTo(superView);
        make.width.height.mas_equalTo(superView);
    }];
}

- (void)setNavigationStyle
{
    [self setNavigationBarTransparent];
//    self.navigationBar.backgroundColor = [UIColor whiteColor];
}

@end
